﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace gChartSharp
{
    /// <summary>
    /// 
    /// </summary>
    public class MapChart : ChartBase
    {
        /// <summary>
        /// 
        /// </summary>
        public override ChartType ChartType { get { return ChartType.t; } }


        #region Member Variables
        private GeographicalAreaParam mGeographicalArea;
        private SubRegionParam mSubregion;
        private MapColorParam mColor;
        private SolidFillParam mBackground;
        #endregion


        #region Properties
        public GeographicalAreaParam GeographicalArea
        {
            get { return mGeographicalArea ?? (mGeographicalArea = new GeographicalAreaParam()); }
            set { mGeographicalArea = value; }
        }


        public SubRegionParam SubRegions
        {
            get { return mSubregion ?? (mSubregion = new SubRegionParam()); }
            set { mSubregion = value; }
        }


        public MapColorParam MapColor
        {
            get { return mColor ?? (mColor = new MapColorParam()); }
            set { mColor = value; }
        }


        public SolidFillParam Background
        {
            get { return mBackground ?? (mBackground = new SolidFillParam()); }
            set { mBackground = value; }
        }
        #endregion


        /// <summary>
        /// 
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="geoArea"></param>
        public MapChart(int width, int height, GeographicalArea geoArea)
        {
            if (width > 440 || height > 220)
                throw new ChartException("MapChart size cannot exceed 440x220.");

            this.Size = new SizeParam(width, height);
            this.Data = new DataSeriesParam(EncodingType.Simple);
            this.GeographicalArea = new GeographicalAreaParam(geoArea);
            this.Background = new SolidFillParam(SolidFillType.bg, Color.White);
        }

   
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string GetURL()
        {
            if (this.Data.DataSets.Count > 0)
            {
                if (this.Data.DataSets.Count > 1)
                    throw new ChartException("Only one data set is allowed for a MapChart.");

                if (this.Data.DataSets[0].Length == this.SubRegions.Countries.Count || this.Data.DataSets[0].Length == this.SubRegions.US_States.Count)
                {
                    StringBuilder sb = CreateBaseURL();
                    RenderIChartParam(mGeographicalArea, ref sb);
                    RenderIChartParam(mColor, ref sb);
                    RenderIChartParam(mBackground, ref sb);
                    RenderIChartParam(mSubregion, ref sb);
                    return sb.ToString();
                }
                else
                    throw new ChartException("The number of SubRegions must match the number of data points.");
            }
            else
            {
                StringBuilder sb = CreateBaseURL();
                RenderIChartParam(mGeographicalArea, ref sb);
                RenderIChartParam(mColor, ref sb);
                RenderIChartParam(mBackground, ref sb);
                RenderIChartParam(mSubregion, ref sb);
                return sb.ToString();
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string GetHTML()
        {
            return "";
        }
    }





} 